﻿using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.ViewModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using WebServerConnectorDll;

namespace FruitManagerApp
{
    public class VIPEditViewModel : NotificationObject
    {
        private VIPEdit gWindow;
        private CVIP gVIP;
        private VIPViewModel gVIPViewModel;

        public VIPEditViewModel(VIPEdit pWindow, VIPViewModel pVIPViewModel, CVIP pVIP)
        {
            gWindow = pWindow;
            gVIP = pVIP;
            gVIPViewModel = pVIPViewModel;

            Initialize();
        }

        public void Initialize()
        {
            UID = gVIP.UID;
            Name = gVIP.Name;
        }

        private int uid;
        public int UID
        {
            get
            {
                return uid;
            }

            set
            {
                uid = value;
                RaisePropertyChanged("UID");
            }
        }

        private String name;
        public String Name
        {
            get
            {
                return name;
            }

            set
            {
                name = value;
                RaisePropertyChanged("Name");
            }
        }

        private int integral;
        public int Integral
        {
            get
            {
                return integral;
            }

            set
            {
                integral = value;
                RaisePropertyChanged("Integral");
            }
        }

        protected DelegateCommand<object> saveCommand;
        public DelegateCommand<object> SaveCommand
        {
            get
            {
                return saveCommand ?? (saveCommand = new DelegateCommand<object>(ExcuteSaveCommand));
            }
        }

        protected virtual void ExcuteSaveCommand(object obj)
        {
            API.UpdateVIP(new CVIP(UID, Name, Integral), gVIP.UID);
            gVIPViewModel.UpdateList();
            gWindow.Close();
        }

        protected DelegateCommand<object> quitCommand;
        public DelegateCommand<object> QuitCommand
        {
            get
            {
                return quitCommand ?? (quitCommand = new DelegateCommand<object>(ExcuteQuitCommand));
            }
        }

        protected virtual void ExcuteQuitCommand(object obj)
        {
            gWindow.Close();
        }
    }
}
